package leetcode;

public class _1080 {
    /**
     *根到叶路径上的不足节点
     */
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    class Solution {
        public TreeNode sufficientSubset(TreeNode root, int limit) {
            limit -=root.val;
            if(root.left==null&&root.right==null){
                return limit>0?null:root;
            }
            if(root.left!=null)root.left = sufficientSubset(root.left,limit);
            if(root.right!=null)root.right = sufficientSubset(root.right,limit);
            return root.left==null&&root.right==null?null:root;
        }
    }
}
